package com.longcai.cm.base.bean;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * @author origin
 */
@Data
@ApiModel(description = "分页信息")
public class PageVo<T> {

    @ApiModelProperty(required = true, notes = "数据信息", example = "[]")
    private List<T> content;

    @ApiModelProperty(required = true, notes = "页码", example = "1")
    private long pageNum;

    @ApiModelProperty(required = true, notes = "单页数据量", example = "10")
    private long pageSize;

    @ApiModelProperty(required = true, notes = "总数据量", example = "213")
    private long total;

    @ApiModelProperty(required = false, notes = "统计总数", example = "213")
    private Double amount;

    private String msg;

    private int code;

    public PageVo(List<T> rows, int total) {
        super();
        this.content = rows;
        this.total = total;
        this.code = 0;
        this.msg = "";
    }

    public PageVo(PageInfo<T> page) {
        this.total = page.getTotal();
        this.code = 0;
        this.msg = "";

        this.pageNum = page.getPageNum();
        this.pageSize = page.getPageSize();
        this.content = page.getList();
    }

    public String convertPage() {
        long limit = (pageNum - 1) * pageSize;
        return " limit " + limit + ", " + pageSize;
    }

    public String convertPage(Integer currentPage, Integer rows) {
        int limit = (currentPage - 1) * rows;
        return " limit " + limit + ", " + rows;
    }

    public PageVo() {
        super();
    }

    @Override
    public String toString() {
        return "PageVo [content=" + content + ", total=" + total + "]";
    }

}
